<?php

class IndexController extends ControllerBase
{

    public function indexAction()
    {
    	//$test = new Products();
		//echo "Total of products: " . $test->getTotal();
    }
	
	public function testAction()
	{
		$pro = Products::find();
		echo "Total of products: " . count($pro). "\n";
		
		foreach ($pro as $p) 
		{
			//$pro = Products::findFirst();
			//echo "Total of products: " . $pro->item(); 
			echo "This item is: " . $p->item . "\n";
			echo "Quantity of this product: " . $p->qty;	
		}
	}
	
	public function insertProductAction()
	{
		$pro = new Products();
		$pro->item = "Test item";
		$pro->qty = 100;
		
		if($pro->save()==FALSE)
		{
			echo "We can't store product right now \n";
			foreach ($pro->getMessages() as $message) 
			{
				echo $message, "\n";
			}
		}
		else 
		{
			echo "Great, a new product was saved successfully!";	
		}
	}
	
	
}

